from flask import Blueprint, render_template, redirect, request,current_app
from app.blueprints.user.models import User
from app.extensions import db

bp = Blueprint('main', __name__,
               template_folder='templates',
               static_folder='static')

@bp.route('/')
def index():
    users = User.query.all()
    return render_template('user_index.html', users=users)

@bp.route('/add_user', methods=['POST'])
def add_user():
    username = request.form['username']
    email = request.form['email']
    new_user = User(username=username, email=email)
    db.session.add(new_user)
    db.session.commit()
    return redirect('/')

@bp.route('/test')
def test():
    current_app.logger.info('test')
    return 'test'